package middleware

import (
	"fmt"
	"hft/global"
	"net"

	"github.com/gin-gonic/gin"
)

// 判断ip所属

func GetIpRegion() gin.HandlerFunc {
	return func(c *gin.Context) {
		ip := net.ParseIP(c.ClientIP())
		record, _ := global.OC_GEO.City(ip)
		fmt.Println("当前地区", record.Country.IsoCode, ip)
		region := record.Country.IsoCode
		if region == "" || region == "PRIVATE" || region == "CN" {
			c.Header("lang", "zh-HK")
		} else {
			c.Header("lang", "zh-CN")
		}
		c.Next()
	}

}
